package com.example.demo.config;

import lombok.Data;

@Data
public class Result<T> {
    /**
     * 返回处理消息
     */
    private String message = "成功！";

    /**
     * 返回代码(默认成功 20000)
     */
    private Integer code = 20000;

    /**
     * 返回数据对象 data
     */
    private T data;

    public Result() {
    }

    public static Result<Object> ok() {
        Result<Object> r = new Result<Object>();
        return r;
    }

    public static Result<Object> ok(String msg) {
        Result<Object> r = new Result<Object>();
        r.setMessage(msg);
        return r;
    }
    public static Result<Object> ok(Object data) {
        Result<Object> r = new Result<Object>();
        r.setData(data);
        return r;
    }
    public static Result<Object> ok(String msg, Object data) {
        Result<Object> r = new Result<Object>();
        r.setMessage(msg);
        r.setData(data);
        return r;
    }
    public static Result<Object> fail(int code, String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode(code);
        r.setMessage(msg);
        return r;
    }

    public static Result<Object> fail(int code, String msg, Object data) {
        Result<Object> r = new Result<Object>();
        r.setCode(code);
        r.setMessage(msg);
        r.setData(data);
        return r;
    }


}
